package com.pomr.controller.test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pomr.util.common.ResponseData;

@Controller
public class UPLoadData {
	@RequestMapping(value="/uploaddata",method=RequestMethod.POST)
	@ResponseBody
	public ResponseData searchDatas(HttpServletRequest request,@RequestBody Map<String,String> map){
		System.out.println(map.get("data"));
		ResponseData pd = null;
		try {
			Map<String, Object> parammap = new HashMap<String, Object>();
			//获取报文
			String bodyjson = map.get("data").toString();
			String str = strTo16(bodyjson);
			parammap.put("data", str);
			String res = HttpUtil.doPost("http://222.173.105.42:8092/QingDaoData/data", parammap);
			System.out.println(res);
			pd = ResponseData.ok();
			pd.putDataValue("param", str);
			pd.putDataValue("res", res);
		} catch (Exception e) {
			e.printStackTrace();
			pd = ResponseData.custom("异常："+e.getMessage());
		}
		return pd;
	}
	
	//转16进制
	public String strTo16(String s) {
        String str = "";
        for (int i = 0; i < s.length(); i++) {
            int ch = (int) s.charAt(i);
            String s4 = Integer.toHexString(ch);
            str = str + s4;
        }
        return str;
    }
}
